package com.example.jpetstoreclient.controller;

import com.example.jpetstoreclient.common.CommonResponse;
import com.example.jpetstoreclient.domain.Collection;
import com.example.jpetstoreclient.service.CollectionService;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Validated
@CrossOrigin
@RestController
@RequestMapping("/collect")
public class CollectionController {
    @Autowired
    private CollectionService collectionService;

    @GetMapping("/{id}")
    public CommonResponse<List<Collection>> getAll(@PathVariable("id") @NotNull(message = "用户ID不能为空") int user_id){
        return collectionService.getAllCollections(user_id);
    }

    @DeleteMapping("/delete/{id}")
    public CommonResponse<Object> delete(@PathVariable("id") @NotNull(message = "收藏ID不能为空") int id){
        return collectionService.deleteCollection(id);
    }

    @PostMapping("/save")
    public CommonResponse<Collection> save(@RequestParam("user_id") @NotNull(message = "用户ID不能为空") int user_id,
                                           @RequestParam("animal_id") @NotNull(message = "商品ID不能为空") int animal_id){
        return collectionService.addCollection(user_id, animal_id);
    }
}
